package com.tshopping.service.impl;

import com.tshopping.bean.Goods;
import com.tshopping.bean.OrderDetails;
import com.tshopping.bean.Parameter;
import com.tshopping.dao.AddressDao;
import com.tshopping.dao.GoodsDao;
import com.tshopping.dao.OrderDetailsDao;
import com.tshopping.dao.ParameterDao;
import com.tshopping.service.OrderDetailsService;
import com.tshopping.service.OrderService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * @name: OrderDetailsServiceImpl
 * @description: 订单详情业务层类
 * @author: Jackeys
 * @date: 2021-01-31 09:51
 */
@Service(value = "orderDetailsService")
@Transactional
public class OrderDetailsServiceImpl implements OrderDetailsService {

    @Autowired
    private OrderDetailsDao orderDetailsDao;

    @Autowired
    private AddressDao addressDao;

    @Autowired
    private GoodsDao goodsDao;

    @Autowired
    private ParameterDao parameterDao;

    @Override
    /**
     * @description 添加用户订单详情
     * @Param: orderDetails
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-31 09:53
     */
    public ResponseData addOrderDetails(OrderDetails orderDetails) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",orderDetailsDao.insertOrderDetailsByAllData(orderDetails));
        return responseData;
    }

    @Override
    /**
     * @description 获取订单详情
     * @Param: order
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-31 09:54
     */
    public ResponseData getOrderDetails(int order,int address) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("address",addressDao.selectAddressById(address));
        ArrayList<OrderDetails> orderDetailsList=orderDetailsDao.selectOderDetailsByOrderId(order);
        ArrayList<Goods> goodsList=new ArrayList<>();
        ArrayList<Parameter> parameters=new ArrayList<>();
        for(OrderDetails orderDetails:orderDetailsList){
            goodsList.add(goodsDao.selectGoodsByGoodsId(orderDetails.getGoods()));
            parameters.add(parameterDao.selectParameterById(orderDetails.getParameter()));
        }
        responseData.putDataValue("orderDetailsList",orderDetailsList);
        responseData.putDataValue("goodsList",goodsList);
        responseData.putDataValue("parameterList",parameters);
        return responseData;
    }
}
